package com.c.ctgproject.ui.files

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.c.ctgproject.base.BaseViewModel
import com.c.ctgproject.http.ApiMethods
import com.c.ctgproject.utils.MyLog
import com.c.ctgproject.utils.awaitSync
import com.c.ctgproject.utils.launch
import com.c.ctgproject.utils.userToken
import okhttp3.MultipartBody

class FileUploadPhotoVideoViewModel : BaseViewModel() {

    private val _upPhoto = MutableLiveData<String>()
    val upPhoto: LiveData<String> get() = _upPhoto


    private val _old = MutableLiveData<String>()
    val oldPhoto: LiveData<String> get() = _old

    //上传车辆照片
    fun upPhotoAndVideo(token: String, parts: ArrayList<MultipartBody.Part>) {
        launch({
            _upPhoto.value = ApiMethods.getApiService().uploadVideo(token, parts).awaitSync()
        }, {
            mError.value = it.message.toString()
        })
    }

    //获取已上传的图片和视频
    fun getOldPhotoVideo(carCode: String) {
        MyLog.d("上传的carcode:$carCode")
        launch {
            _old.value = ApiMethods.getApiService().getOldPhotoVideo(userToken, carCode).awaitSync()
        }
    }

}